﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace testgame
{
    public partial class FrmMain : Form
    {

        /*游戏对象说明*/
        private Game _game;
        bool bol = false;//声明关于游戏能否开始的bool型

        public FrmMain(FormStart formStart)//FrmMain为FormStart的子窗体程序
        {
            InitializeComponent();

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {

        }
 
        private void Panel_Paint(object sender, PaintEventArgs e)
        {

        }

        private void GameArea_Paint(object sender, PaintEventArgs e)
        {
            //绘制游戏区域
            if (bol == true)
            {
                if (_game != null)
                {
                    _game.DrawGame(e.Graphics, this.gameArea.Size);
                    gameArea.Invalidate();
                    //游戏胜利或失败时，出现胜利和失败字样后，直接关闭窗口
                    if (LaunchCanister.health <= 0 || LaunchCanister.score == 100)//游戏失败或者胜利时回到开始界面
                    {
                        _game.DrawGame(e.Graphics, this.gameArea.Size);
                        this.Close();
                    }
                }
              
            }
           
        }

        /// <summary>
        /// 处理按下键盘
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {

            if (_game != null)
            {
                LaunchCanister.Keydown(e.KeyCode);

            }
        }

        //处理松开键盘
        private void FrmMain_KeyUp(object sender, KeyEventArgs e)
        {
            if (_game != null)
            {
                LaunchCanister.Keyup(e.KeyCode);
                //LaunchCanister.LCImage = Properties.Resources.飞机;

            }
        }

        private void GameArea_Load(object sender, EventArgs e)
        {
            //初始化游戏类
            _game = new Game();
            gameArea.Invalidate();
        }

        //出现关于我的界面
        private void AboutMe_Click(object sender, EventArgs e)
        {
            FrmAboutme frm = new FrmAboutme();
            frm.ShowDialog();
        }

        //出现“经鉴定，您已药石无医”的界面
        private void 真ToolStripMenuItem_Click(object sender, EventArgs e)
        { 
            realc realc = new realc();
            realc.ShowDialog();
        }

        private void 假ToolStripMenuItem_Click(object sender, EventArgs e)
        { 
        }

        //开始游戏
        private void playGame_Click(object sender, EventArgs e)
        {

            _game = new Game();
            this.gameArea.Invalidate();
        }

        //使游戏开始
        private void btnStart_Click(object sender, EventArgs e)
        {
            bol = true;
            gameArea.Invalidate();
        }

        //出现“王者攻略”的帮助界面
        private void 王者攻略汪ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            King king = new King();
            king.ShowDialog();
        }

        //出现“正常攻略”的帮助界面
        private void 正常攻略ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            normal normal = new normal();
            normal.ShowDialog();
        }

        //使游戏继续进行
        private void ContinueCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            continueCToolStripMenuItem.Checked = true;
            bol = true;//游戏继续
            gameArea.Invalidate();
            continueCToolStripMenuItem.Checked = false;
        }

        //使游戏暂停
        private void SuspendSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            suspendSToolStripMenuItem.Checked = true;
            bol = false;//游戏暂停
            suspendSToolStripMenuItem.Checked = false;
        }
       
        //游戏进程中的退出
        private void ExitEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            exitEToolStripMenuItem.Checked = true;
            this.Close();
        }

        private void 你是真的菜吗马ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void gameGToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        //未开始游戏时当点窗体的x时出现提示窗体
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(MessageBox.Show ("少侠确定要离开吗？","!!!提示",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                e.Cancel = false;
                Application.Exit();
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}
